from common.unit import AndroidUI
from common.home_page import HomePageObject
from common.qr_code import QRCodeX
from object.lnitial.lnitial_page import LnitialObject
from object.storage.storage_page import StorageObject
from common.request_result import GetCode
import time


#科室装箱，入库操作
class StorageBoxTest:
    def __init__(self):
        self.unit = AndroidUI
        self.home = HomePageObject()
        self.qrcode = QRCodeX()
        self.ln = LnitialObject()
        self.st = StorageObject()
        self.get_code = GetCode()
        self.driver = AndroidUI.get_webdriver()

    # 返回
    def back_button(self):
        self.driver.keyevent(4)

    # 清理人登录
    def check_login(self):
        # self.unit.scan(self.qrcode.zhaoqingli)
        try:
            self.ln.system_button()
            self.unit.scan(self.qrcode.zhaoqingli)
            print("登录成功")
        except:
            print("已经登录")

    # 点击入库按钮，进入入库界面，并且返回首页
    def enter_storage_click(self):
        try:
            self.home.enter_button().click()
            self.st.lib_check_bag_button()
            print("点击入库按钮进入入库界面成功")
            AndroidUI().write_result("点击入库按钮进入入库界面", "成功")
            self.back_button()
        except:
            print("点击入库按钮进入入库界面失败")
            AndroidUI.capture()
            AndroidUI().write_result("点击入库按钮进入入库界面", "失败")
            # self.driver.quit()

    # 扫码进入入库界面
    def enter_storage_scan(self):
        try:
            # self.home.enter_button().click()
            self.unit.scan(self.qrcode.zancunjian)
            self.st.lib_check_bag_button()
            time.sleep(1.5)
            print("扫码进入入库界面成功")
            AndroidUI().write_result("扫码进入入库界面", "成功")

        except:
            print("扫码进入入库界面失败")
            AndroidUI.capture()
            AndroidUI().write_result("扫码进入入库界面", "失败")
    #
    # # 点击装箱按钮进入装箱界面
    # def enter_box_page(self):
    #     try:
    #         self.st.lib_packing_button().click()
    #         self.st.listbox_button()
    #         print("点击装箱按钮应该不能进入装箱界面失败")
    #         AndroidUI.capture()
    #         AndroidUI().write_result("点击装箱按钮应该不能进入装箱界面", "失败")
    #     except:
    #         print("点击装箱按钮应该不能进入装箱界面成功")
    #
    #         AndroidUI().write_result("点击装箱按钮应该不能进入装箱界面", "成功")


    # 点击装箱按钮进入装箱界面
    def enter_box_page(self):
        try:
            self.st.lib_packing_button().click()
            self.st.lib_enter_button()
            print("点击装箱按钮应该不能进入装箱界面成功")

            AndroidUI().write_result("点击装箱按钮应该不能进入装箱界面", "成功")
        except:
            print("点击装箱按钮应该不能进入装箱界面失败")
            AndroidUI.capture()
            AndroidUI().write_result("点击装箱按钮应该不能进入装箱界面", "失败")



    # 返回首页
    def back_home(self):
        try:
            #todo 退出首页没有二次确认
            self.st.back_button().click()
            self.home.home_page()
            print("返回首页成功")
            AndroidUI().write_result("返回首页", "成功")
        except:
            print("返回首页失败")
            self.back_button()
            AndroidUI.capture()
            AndroidUI().write_result("返回首页界面", "失败")

    def start_test(self):
        self.check_login()
        self.enter_storage_click()
        self.enter_storage_scan()
        self.enter_box_page()
        self.back_home()


if __name__ == '__main__':
    st = StorageBoxTest()
    # st.check_login()
    # time.sleep(3)
    # st.unit.scan(QRCodeX().zancunjian)

    st.start_test()
